#ifndef __GLOBAL_H__
#define __GLOBAL_H__

#include <boost/pool/detail/singleton.hpp>
#include <map>
#include <string>
#include <list>
#include <iostream>

#include "Object.h"


using boost::details::pool::singleton_default;	//单件命名空间
using namespace std;
namespace RisingStar
{
	//数据库描述符
	typedef struct
	{
		map<string,string> property;
		map<string,map<string,map<string,string> > > tableProperty; //map<对象,map<信号名,map<属性,属性值 > > >
	}TDatabaseCfg;
	
	typedef struct
	{
		map<string,map<string,string> >	sems;	//信号量
		map<string,string> property;			//对象的属性
	}TDicParam;
	

	class Global
	{
	public:
		Global(void);
		~Global(void);
		
		
		void Print();
		
		bool ImportDic(string dicPath);	//导入字典表，XML格式，路径为指定模式
		bool CreateObjects();		//建立对象
		CObject::ObjectPtr GetObjectCopy(string objTypeCode);
		bool CreateMySQLFile(string outFileName,string databaseName="ParkingSpaceData",TDatabaseParam* dbParam = NULL);	//建立MySQL文件
		
		bool GetDatabasePtr(string key,DatabasePtr& dataPtr );
		bool GetDatabaseCfg(string dFile);
		bool GetDicInfo(string objType,string semID,string searchParam,string& rst);
		bool GetSemType(string in,string& out,string cType = "ID2类型名" );
		bool GetFormula(string formulaType,string in,string& out);
		//存储远程数据库阵列信息
		
		map<string,TDatabaseParam > RemoteDatabaseArr;	//远程数据库数组 map<"省编号/手机号码段",map<属性,值> >
	public:
		///全局配置变量
		///map<变量名,变量值>
		map<string,string> Values;
		
		///信号字典表，用于记录字典表的所有信息
		///map<对象类型,map<信号ID,map<信号属性,信号值 > > >
		///map<string,map<string,map<string,string> > > Dic;
		map<string,TDicParam> Dic;
		
		
		map<string,string> ObjTypeMap;
		map<string,DEF_REQUEST_CALLBACK> RequestCallbackMap;	//	
		
		TDatabaseCfg	DatabaseCfg;	//数据库配置参数
	protected:	
		map<string,CObject::ObjectPtr> ObjectMap;		
		//信号类型名和信号类型编码对应表, map<"类型名2ID|ID2类型名",map<ID|信号类型,信号类型|ID> >
		map<string,map<string,string> > SemType;
		//map<string,string> FormulaMap;
		map<string,map<string,string> > FormulaMap;
		
	private:
		void RegisterObject(CObject::ObjectPtr obj);
		string MatchSemID(string objType,string attribute,string value);
		
		//objType：对象类型
		//nesSem:必要的信号
		//optSem:可选的信号
		bool RegisterRequestSem(string objType,string request,string nesSem,string optSem);
	};
};
//#define sGlobal Global::instance()
typedef singleton_default<RisingStar::Global> GlobalInstance;
#define sGlobal GlobalInstance::instance()
#endif
